/**
 * 用于页面通信的简易bus
 */

let bus = {};

function on(key, func) {
  if(!bus[key]){
    bus[key] = [func];
  }else{
    bus[key].push(func)
  }
 }

 
 function emit(key, params) {
  if(!bus[key]) return;
  for(let v of bus[key]){
    v(params)
  }
}


function off(key) {
  bus[key] && delete bus[key];
}


module.exports = {
  bus,
  on,
  emit,
  off
}